<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>

  <div id="app">
    <h3>{{ title }}</h3>
    <div>
      <button @click="count--">-</button>
      <span>{{ count }}</span>
      <button @click="count++">+</button>
      <button @click="killSelf">销毁</button>
    </div>
  </div>
  <script src="https://cdn.bootcdn.net/ajax/libs/vue/2.7.14/vue.js"></script>
  <script>
    const app = new Vue({
      el: '#app',
      data: {
        count: 100,
        title: '计数器',
        timer: null
      },
      methods: {
        killSelf() {
          this.$destroy()
        }
      },
      beforeCreate() {
        console.log(this, '创建前');
      },
      created() {
        console.log(this, '创建后');
        this.timer = setTimeout(console.log('1'), 1000)
      },
      beforeMount() {
        console.log(document.querySelector('h3').innerHTML, '挂载前');
      },
      mounted() {
        console.log(document.querySelector('h3').innerHTML, '挂载后');
      },
      beforeUpdate() {
        clearTimeout(this.timer)
        console.log(document.querySelector('span').innerHTML, '修改之前的内容');
      },
      updated() {
        console.log(document.querySelector('span').innerHTML, '修改后的内容');
      },
      beforeDestroy() {
        console.log('销毁前');
      },
      destroyed() {
        console.log('销毁后');
      }
    })
  </script>
</body>

</html>